<?php
namespace app\api\controller;

class Register
{
    public function register()
    {
        $data = request()->post();
        $phone = $data['userName'];
        $pwd = $data['password'];
        $pwdC = $data['passwordConfirm'];
        if ($pwd !== $pwdC) {
            return error('密码与确认密码不一致');
        }
        $field = ['userName', 'password', 'passwordConfirm'];
        return api_response(['post'], [], ['token'=>strtoupper(md5($phone . $pwd))]);
    }

    /**
     * 手机号登录
     * @return array
     */
    public function phoneLogin()
    {
        $phone = $_POST['userMobile'];
        $pwd   = $_POST['password'];
        $field = ['userMobile', 'password'];
        return api_response(['post'], [], ['id'=>1, 'token'=>md5(123456)]);
    }

    //微信登录
    public function wechatLogin()
    {
        $field = ['nickname', 'openid', 'headImg'];
        return api_response(['post'], [], ['id'=>1, 'token'=>md5(123456)]);
    }

    public function verifyCode()
    {
        $code = rand(1000, 9999);
        $field = ['userMobile'];
        return api_response(['post'], [], ['verifyCode'=>$code]);
    }

    public function resetPassword()
    {
        $pwd = $_POST['password'];
        $pwdC = $_POST['passwordConfirm'];
        $field = ['password', 'passwordConfirm'];
        if ($pwd !== $pwdC) {
            return error('密码与确认密码不一致');
        }
        return api_response(['post'], [], []);
    }
}